import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

// 算法：“

// 12、实现算法题,自定义函数bubbleSort,使用冒泡算法,实现数组元素升序排序,
// 例如:var arr = [4, 23, 14, 52, 66, 1134, 567, 23]
// bubbleSort(arr)
// console.log(arr);//[4, 14, 23, 23, 52, 66, 567, 1134]

function bubbleSort(arr) {
  // 方案1：
  // arr.sort((a, b) => a - b)

  // 方案2：
  for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < arr.length; j++) {
      if(arr[j] > arr[j + 1]) {
        const temp = arr[j + 1]
        arr[j + 1] = arr[j]
        arr[j] = temp
      }
    }
  }
}

const arr = [4, 23, 14, 52, 66, 1134, 567, 23];
bubbleSort(arr);
console.log(arr); //[4, 14, 23, 23, 52, 66, 567, 1134]

// 13、实现算法题：数组去重，例如有数组：

// 自定义函数getNewArr(arr),实现



function getNewArr(arr) {
  return [...new Set(arr)]
}

var arr1 = [1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 3]
console.log(getNewArr(arr1)) //[1, 2, 3, 4, 5, 6]